package com.superman.supermarket.client.composite.sku.bottom;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Widget;
import com.superman.mvpframe.client.gin.XGinjector;
import com.superman.supermarket.client.event.SkuPageEvent;
import com.superman.supermarket.client.event.SkuPageEvent.SkuPageEventType;
import com.superman.supermarket.client.gin.ShopGinjector;

/**
 * 商品详情底部模块
 * 
 * @author superman
 * @version 2018年7月24日下午9:30:49
 */
public class SkuDetailBottomModule extends Composite {

	interface SkuDetailBottomModuleUiBinder extends UiBinder<Widget, SkuDetailBottomModule> {
	}

	private static SkuDetailBottomModuleUiBinder uiBinder = GWT.create(SkuDetailBottomModuleUiBinder.class);

	@UiField
	HTML collectbtn;
	private boolean isFav;// 当前的收藏状态

	/**
	 * 构造方法
	 * 
	 * @author superman
	 * @version 2018年7月24日 下午9:30:52
	 */
	public SkuDetailBottomModule() {
		initWidget(uiBinder.createAndBindUi(this));
	}

	@UiHandler("addcartbtn")
	void addCart(ClickEvent event) {
		SkuPageEvent skuPageEvent = new SkuPageEvent(SkuPageEventType.SHOW_POP_TO_ADDCART);
		XGinjector.INSTANCE.getEventbusController().fire(skuPageEvent);
	}

	@UiHandler("buybtn")
	void buy(ClickEvent event) {
		SkuPageEvent skuPageEvent = new SkuPageEvent(SkuPageEventType.SHOW_POP_TO_BUY);
		XGinjector.INSTANCE.getEventbusController().fire(skuPageEvent);
	}

	@UiHandler("collectbtn")
	void collectChange(ClickEvent event) {
		SkuPageEvent skuPageEvent = new SkuPageEvent(isFav ? SkuPageEventType.UNCOLLECT : SkuPageEventType.COLLECT);
		XGinjector.INSTANCE.getEventbusController().fire(skuPageEvent);
	}

	@UiHandler("cartbtn")
	void pushToCartPage(ClickEvent event) {
		XGinjector.INSTANCE.getMyPlaceController().push(ShopGinjector.INSTANCE.getMyPlaceFactory().getCartPlace());
	}

	/**
	 * 设置收藏
	 * 
	 * @author superman
	 * @version 2018年8月2日 上午10:11:57
	 * @param isFav
	 */
	public void setFav(boolean isFav) {
		this.isFav = isFav;
		collectbtn.getElement().getStyle().setProperty("color", isFav ? "red" : "#333");
	}

}
